
<template>
    <div class="contract-list-page waiver-of-fees-list">
        <Card>
            <ChangeForm
                :isSP="isSP"
                :formValidate="formValidate"
                :formValidateRule="formValidateRule"
                :dataDict="dataDict"
                :businessSource="businessSource"
                @showModal="showModal"
                @getList="getList"
            />
            <ChangeTable
                :isSP="isSP"
                :formValidate="formValidate"
                :dataDict="dataDict"
                :businessSource="businessSource"
                :contractTable="contractTable"
                @getList="getList"
                @showContractDetial="showContractDetial"
            />
        </Card>
        <ActivatedCase
            :isSP="isSP"
            :getDataFn="getDataFn"
            :dataDict="dataDict"
            :modal="modal"
            modalTitle="已激活案件列表"
            @showContractDetial="showContractDetial"
            @closeModal="closeModal"
        />
        <button @click="showContractDetial({contractNo:'N888888'})">豁免费用详情</button>
    </div>
</template>
<script>
    // api
    import {mapGetters} from "vuex";
    import {findActivatedContractList, getManageCustInfoChangeList} from "_p/basic/api/contract/post-loan-info-change";
    import {getDictDataList} from "_p/basic/assets/contract/js/utils";

    import {businessSource, channelType} from "_p/basic/api/contract/channel-type/channel-type";
    import {isPhoneValiate} from "_p/basic/assets/contract/js/utils";

    import ChangeForm from "./ChangeForm";
    import ChangeTable from "./ChangeTable";
    import ActivatedCase from "_p/basic/pages/contract/common/activated-case/index";

    export default {
    // 豁免费用
    name: "WaiverOfFeesList",
    components: {
        ChangeForm,
        ChangeTable,
        ActivatedCase
    },
    props: {},
    data() {
        return {
            pageNo: 1,
            // 是否是合作商
            isSP: false,
            loading: false,
            // 日期区间
            isDateErr: false,
            formValidate: {
                applyNo: "", // 申请编号
                contractNo: "", // 合同号
                custName: "", // 客户名称
                pageNumber: 1,
                pageSize: 50,
                processStatus: null
            },
            formValidateRule: {
                phone: [
                    {
                        validator: (rule, value, callback) => {
                            isPhoneValiate(rule, value, callback);
                        },
                        trigger: "blur"
                    }
                ]
            },

            contractTable: {
                current: 1, // 表格当前页
                pages: 0,
                searchCount: false,
                size: 10,
                total: 0,
                orders: [],
                records: []
            },
            // TODO: 数据字典数据 ----- 案件类型
            //  处理状态(processStatus)   来源(dataSource)  变更主体(PersonRoleType)  案件类型(businessSource)
            dicttArr: ["processStatus", "dataSource", "PersonRoleType", 'businessSource'],
            dataDict: {}, // 数据字典
            processStatusDict: [],
            contractStatusDict: [],
            processModeDict: [],
            modal: false
        };
    },
    created() {
        this.isSP = channelType(this.$route.meta.params);
        // businessSource 通过 roleType 获取 值: BUSINESS_PEOPLE / SP
        this.businessSource = businessSource(this.roleType);
    },
    computed: {
        ...mapGetters({
            userInfo: "userInfo",
            roleType: "roles"
        }),
        getDataFn: () => findActivatedContractList
    },
    mounted() {
        console.group("初始数据：");
        console.log("userInfo:", this.userInfo);
        console.log("pageParams:", this.pageParams);
        console.log("roleType:", this.roleType);
        console.log("isSP:", this.isSP);
        console.log("isApprove:", this.isApprove);
        console.log("contractNo:", this.contractNo);
        console.groupEnd();
    },
    activated() {
        this.init();
    },
    methods: {
        init() {
            this.isSP = channelType(this.$route.meta.params);
            this.getList(this.formValidate);
            this.getDictDataList();
        },
        getDictDataList() {
            getDictDataList(this.dicttArr).then(res => {
                console.group("数据字典:");
                console.log(this.dicttArr.join("  "));
                console.log(JSON.parse(JSON.stringify(res)));
                console.groupEnd();
                this.dataDict = res;
            });
        },
        // 查询
        handleSubmit(name) {
            this.$refs[name].validate(valid => {
                if (valid) {
                    this.loading = true;
                    this.getList(this.formValidate);
                }
            });
        },
        handleReset(name) {
            this.$refs[name].resetFields();
        },
        // 请求table数据
        getList(data) {
            if (!data) data = this.formValidate;
            getManageCustInfoChangeList(data)
                .then(res => {
                    this.loading = false;
                    if (res.code === "0000") {
                        this.contractTable = res.data;
                    } else {
                        this.$Message.error("Fail!");
                    }
                })
                .catch(e => {
                    console.error(e);
                });
        },

        // 弹窗
        showModal() {
            this.modal = true;
        },
        closeModal() {
            this.modal = false;
        },
        showContractDetial(params) {
            if (!params && !params.contractNo) return;
            this.modal = false;
            this.afs.newTab(
                this,
                "projects/basic/pages/contract/fee-waiver/cost-exempt-detial/index",
                "豁免费用详情",
                "ios-add",
                params,
                "cost-exempt-detial-" + this.pageNo,
                [],
                true
            );
            this.pageNo += 1;
        }
    }
};
</script>
<style lang="less" >
@import "../../../../styles/common/form.less";
</style>
